<html>
<head><meta charset="utf-8"><title>Editions and trailing commas in macros? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html">Editions and trailing commas in macros?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222132301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222132301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222132301">(Jan 08 2021 at 22:04)</a>:</h4>
<p>This might potentially be too invasive for an edition, but: how feasible might it be to make <code>,*</code> and <code>,+</code> and similar allow an optional trailing comma automatically, in a new edition?</p>



<a name="222132311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222132311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222132311">(Jan 08 2021 at 22:04)</a>:</h4>
<p>How much breakage does that seem likely to produce?</p>



<a name="222132487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222132487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222132487">(Jan 08 2021 at 22:06)</a>:</h4>
<p>what's the alternative for when a macro author wants the original behavior?</p>



<a name="222132560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222132560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222132560">(Jan 08 2021 at 22:07)</a>:</h4>
<p>Does <code>,*,?</code> work? Because that seems like the easiest place to start</p>



<a name="222133203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222133203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222133203">(Jan 08 2021 at 22:15)</a>:</h4>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> No, it doesn't. If you want to allow an optional trailing comma, you need something like <code>$(...what you have...),* $(,)?</code></p>



<a name="222133539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222133539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222133539">(Jan 08 2021 at 22:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F/near/222132487">said</a>:</p>
<blockquote>
<p>what's the alternative for when a macro author wants the original behavior?</p>
</blockquote>
<p>You could get that by writing <code>$(, $foo:expr)*</code> instead, but under what circumstances would you <em>want</em> that?</p>



<a name="222133654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222133654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222133654">(Jan 08 2021 at 22:18)</a>:</h4>
<p>Purely anecdata, but I’ve never not wanted trailing commas, however the addition of <code>?</code> has made this easy to implement, and just recently I wanted to enforce having a trailing semi-colons to emulate let statements E.g. <code>($(let $name:ident = $exp:expr);+ ;)</code> Im not sure how you’d do that with that new behaviour without also allowing <code>;;</code> at the end.</p>



<a name="222133709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222133709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222133709">(Jan 08 2021 at 22:19)</a>:</h4>
<p><span class="user-mention" data-user-id="219696">@XAMPPRocky</span> Enforcing trailing semicolons would be easy: <code>$(let $name: ident = $exp:expr;)+</code></p>



<a name="222133723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222133723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222133723">(Jan 08 2021 at 22:19)</a>:</h4>
<p>Just move the <code>;</code> inside the repetition parentheses.</p>



<a name="222133732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222133732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222133732">(Jan 08 2021 at 22:19)</a>:</h4>
<p>Ah true</p>



<a name="222133748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222133748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222133748">(Jan 08 2021 at 22:19)</a>:</h4>
<p>It'd be harder to have a syntax for "enforce <em>absence</em> of trailing separator".</p>



<a name="222133760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222133760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222133760">(Jan 08 2021 at 22:20)</a>:</h4>
<p>But I don't mind that being harder. :)</p>



<a name="222153887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222153887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222153887">(Jan 09 2021 at 04:51)</a>:</h4>
<p>Feels unfortunate that doing this would immediately allow an <em>extra</em> comma in all the macros that support it explicitly, and there'd be no semver way to remove that support.</p>



<a name="222153927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222153927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222153927">(Jan 09 2021 at 04:52)</a>:</h4>
<p>Maybe better as something for the "macros 2.0" list, like that previous conversation about keywords.</p>



<a name="222154283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222154283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222154283">(Jan 09 2021 at 05:02)</a>:</h4>
<p>I think there is good reason to have direct support for separator characters with no option for trailing separator, for example I probably don't want <code>a + b + c +</code> to work. Compared to the mandatory trailing separator case which is fairly easy to get, you have to go through some messy encoding to get the effect of <code>$(e),*</code> if it wasn't built in</p>



<a name="222154364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222154364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222154364">(Jan 09 2021 at 05:04)</a>:</h4>
<p>Also, if it's not the last thing in the parse, too many <code>,?</code> may result in a lot of backtracking during the parse</p>



<a name="222179350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222179350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222179350">(Jan 09 2021 at 17:18)</a>:</h4>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> Ah, very good point. <code>+</code> is a convincing case for why trailing separators should not always be allowed.</p>



<a name="222195371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222195371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222195371">(Jan 09 2021 at 23:42)</a>:</h4>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> That doesn’t work though right? I just checked and you can’t seem to be able to write <code>$(foo)++</code> and have it work like that.</p>



<a name="222195400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222195400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222195400">(Jan 09 2021 at 23:43)</a>:</h4>
<p>that's possible. Ideally the separator should be another pattern instead of just a token</p>



<a name="222195518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222195518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222195518">(Jan 09 2021 at 23:46)</a>:</h4>
<p>Right but to allow that, that would probably require a new syntax, and if that’s the case you could have it account for “allow this pattern to be trailing or not”</p>



<a name="222195597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222195597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222195597">(Jan 09 2021 at 23:49)</a>:</h4>
<p>that works for me, as long as all options are available (mandatory / optional / prohibited final separator)</p>



<a name="222203828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222203828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222203828">(Jan 10 2021 at 03:42)</a>:</h4>
<p>how about writing <code>$($var,)*</code> for mandatory trailing separator, <code>$($var)[,]*</code> for optional trailing separator (<code>[...]</code> like in <a href="https://en.wikipedia.org/wiki/Augmented_Backus%E2%80%93Naur_form#Optional_sequence">ABNF</a>), and <code>$($var),*</code> for no trailing separator?</p>
<p>This would allow later extension to having multiple tokens/token-trees as separators:</p>
<p><code>$($var)[@@]*</code> would have <code>@@</code> as the separator with an optional trailing separator.</p>
<p><code>$($var)(@@)*</code> would have <code>@@</code> as the separator with no trailing separator. <code>$($var),*</code> would be syntax sugar for <code>$($var)(,)*</code>.</p>
<p><code>$($var @@)*</code> would have <code>@@</code> as the separator with a required trailing separator.</p>



<a name="222203893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Editions%20and%20trailing%20commas%20in%20macros%3F/near/222203893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Editions.20and.20trailing.20commas.20in.20macros.3F.html#222203893">(Jan 10 2021 at 03:44)</a>:</h4>
<p>that would make it work in all of the 2015, 2018, and 2021 editions without changing between them</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>